package com.example.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.data.redis.core.script.RedisScript;
import org.springframework.scripting.support.ResourceScriptSource;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * @Description TODO
 * @Date 2024/3/12 14:24
 * @Author ShaoJie Cen
 */
@Component
public class SpringLuaScript {


    // 注册Lua脚本到Spring容器
    @Bean
    public RedisScript<Boolean> limitScript() {
        DefaultRedisScript<Boolean> script = new DefaultRedisScript<>();
        // 指定Lua脚本路径
        script.setScriptSource(new ResourceScriptSource(new ClassPathResource("redis_uuid.lua")));
        // 设置返回结果类型
        script.setResultType(Boolean.class);
        return script;
    }


}

